home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / graphics / jclplasm.arj / JCLPLASM.ASM < prev    next >
Assembly Source File  |  1994-02-04  |  9KB  |  246 lines

  1. ; **************************************************************************
  2. ; **************************************************************************
  3. ; ****                                                                  ****
  4. ; ****  JCL-Plasma v1.3a (C) 1994 JCL-software                          ****
  5. ; ****                                                                  ****
  6. ; ****  This .asm file contains a routine to display a 'plasma' type    ****
  7. ; ****  image.  It requires at least a 386, and 486/33 is recommended.  ****
  8. ; ****  Also required is a file PLASMA.DAT, which contains image,       ****
  9. ; ****  'movement', and colour palette information pregenerated for     ****
  10. ; ****  speed by the file PLGENPLM.C                                    ****
  11. ; ****                                                                  ****
  12. ; ****  This file was compiled using TASM 2.5, and very experienced     ****
  13. ; ****  programmers might want to have a quiet laugh about how badly    ****
  14. ; ****  this is coded... however, this is BY FAR the fastest plasma     ****
  15. ; ****  I have seen, and also runs in FULL 320x200 resolution, at       ****
  16. ; ****  70 fps on my 486DX/33 (Local bus)                               ****
  17. ; ****                                                                  ****
  18. ; ****  Thanks go to Thomas Hagen, whose plasma inspired me to get one  ****
  19. ; ****  that worked full screen, and whose original function I          ****
  20. ; ****  'borrowed' until I finally got round to working one out by      ****
  21. ; ****  myself..                                                        ****
  22. ; ****                                                                  ****
  23. ; ****  Please send any (helpful) comments to me (Jeremy Longley) at    ****
  24. ; ****  jcl1008@cus.cam.ac.uk  (or Selwyn College, CAMBRIDGE, UK)       ****
  25. ; ****                                                                  ****
  26. ; ****                                Jezza (3/2/94 02:06 (groan...))   ****
  27. ; ****                                                                  ****
  28. ; **************************************************************************
  29. ; **************************************************************************
  30.  
  31.  
  32.  
  33.  
  34. .MODEL  tiny
  35.  
  36. ; ****  Macros ****
  37.  
  38. end_process macro return_code
  39.         mov     al,return_code
  40.         mov     ah,4ch
  41.         int     21h
  42.     endm
  43.  
  44. string  macro   str
  45.         mov     ah,09h
  46.         mov     dx,offset str
  47.         int     21h
  48.         endm
  49.  
  50. fopen   macro   file,attrib
  51.         mov     ah,3dh
  52.         mov     al,attrib
  53.         mov     dx,offset file
  54.         int     21h
  55.         endm
  56.  
  57. malloc  macro   amount
  58.         mov     ah,48h
  59.         mov     bx,amount
  60.         int     21h
  61.         endm
  62.  
  63. mfree   macro   where
  64.         mov     ah,49h
  65.         mov     es,where
  66.         int     21h
  67.         endm
  68.  
  69. fread   macro   handle,bytes
  70.         push    ax
  71.         push    ds
  72.         push    ax
  73.         mov     ah,3fh
  74.         mov     bx,[handle]
  75.         mov     cx,bytes
  76.         xor     dx,dx
  77.         pop     ds
  78.         int     21h
  79.         pop     ds
  80.         pop     ax
  81.         endm
  82.  
  83. keyp    macro
  84.         mov     ah,0bh
  85.         int     21h
  86.         or      al,al
  87.         endm
  88.  
  89.  
  90. ; ****  static data ****
  91.  
  92. .CODE
  93.  
  94. org     100h
  95. start:  jmp begin
  96.  
  97. headup  db 13,10,"JCLPLASM v1.3a - (C) 1994 JCL-Software (e-mail jcl1008@cus.cam.ac.uk)",13,10,"$"
  98. noload  db 13,10,7,"Can't open file PLASMA.DAT",13,10,"$"
  99. nomalloc db 13,10,7,"Not enough base memory",13,10,"$"
  100. datf    db "PLASMA.DAT",0
  101. handle  dw 0
  102. plasma_seg  dw 0
  103. move_seg    dw 0
  104. colour_seg  dw 0
  105. count   dw 0
  106.  
  107. ASSUME  DS:@code,ES:@code
  108.  
  109. ; ****  Code ****
  110.  
  111. .386
  112.  
  113. begin:  ; *** Startup section ***
  114.  
  115.         mov     sp,offset tos   ; set new stack
  116.  
  117.         mov     bx,last_inst-start+100h
  118.         shr     bx,4            ; shrink memory usage to program size
  119.         inc     bx              ; in pages (16 bytes)
  120.         mov     ah,4ah
  121.         int     21h
  122.  
  123.         string  headup          ; display header message
  124.  
  125.         malloc  9600+1          ; allocate memory for plasma buffer
  126.         jc      nomem           ; break if not enough memory
  127.         mov     [plasma_seg],ax ; store address
  128.         malloc  2500+1          ; allocate memory for movement buffer
  129.         jc      nomem           ; as above...
  130.         mov     [move_seg],ax
  131.         malloc  1920+1          ; allocate memory for colour buffer
  132.         jc      nomem
  133.         mov     [colour_seg],ax
  134.         jmp     allocok         ; skip the following
  135. nomem:  string  nomalloc        ; tell user no memory
  136.         end_process 255         ; and quit
  137.  
  138. allocok:
  139.         fopen   datf,0          ; open PLASMA.DAT read only
  140.         jnc     loadok          ; oops - not here!
  141.         string  noload          ; so tell user
  142.         end_process 254         ; and quit
  143. loadok: mov     [handle],ax     ; store handle
  144.         mov     ax,[plasma_seg] ; get load segment for plasma data
  145.         mov     cl,4            ; load in 8 steps
  146. loadpl: push    cx              ; store loop count
  147.         fread   handle,9600h    ; read the data
  148.         add     ax,960h         ; increase pointer
  149.         pop     cx              ; restore loop count
  150.         dec     cl              ; decrement loop count
  151.         jnz     loadpl          ; and loop...
  152.  
  153.         mov     ax,[move_seg]   ; read movement data
  154.         fread   handle,40000
  155.         mov     ax,[colour_seg] ; and color data
  156.         fread   handle,30720
  157.  
  158.         ;  *** plasma section ***
  159.  
  160.         mov     ax,13h          ; set video mode 13
  161.         int     10h
  162.         mov     ax,0a000h
  163.         mov     es,ax
  164.  
  165.         xor     ax,ax           ; clear ax
  166.         mov     [count],ax      ; store counter
  167.  
  168. mainloop:
  169. waitfly:
  170.         mov     dx,03dah        ; VGA input status register 1
  171.         in      al,dx           ; load value
  172.         test    al,08           ; vertical retrace??
  173.         je      waitfly         ; if not, try again...
  174.  
  175.         mov     si,[count]      ; source = count *3
  176.         shl     si,1
  177.         add     si,[count]
  178.         mov     dx,3c8h         ; DAC index register
  179.         mov     al,1            ; start with reg 1
  180.         out     dx,al           ; and load
  181.         inc     dx              ; DAC read/write register
  182.         mov     cx,255          ; write 255 items
  183.         push    ds              ; store DS
  184.         mov     ds,[colour_seg] ; address segment
  185.         cld                     ; ensure SI is incremented
  186. setpl:  outsb                   ; load R,G,B
  187.         outsb                   ; Note - REP OUTSB is too fast on
  188.         outsb                   ; some older VGA cards..
  189.         loop    setpl           ; so loop
  190.         pop     ds              ; and restore DS
  191.  
  192.         mov     di,[count]      ; source = count * 4
  193.         shl     di,2
  194.         push    ds              ; save DS (again...)
  195.         mov     ds,[move_seg]   ; get segment address of movement data
  196.         mov     si,[di]         ; load point 1
  197.         mov     bx,[di+2]       ; load point 2
  198.         pop     ds              ; restore DS
  199.  
  200.         push    ds              ; and store it ...
  201.         mov     ds,[plasma_seg] ; get segment of start of plasma
  202.         xor     di,di           ; DI = 0
  203.  
  204.         mov     ch,200          ; y loop = 200 pixels
  205. pl1:    mov     cl,80           ; x loop = 80 * 4 = 320 pixels
  206. pl2:    lodsd                   ; get 4 source pixels
  207.         add     eax,[si+bx]     ; add 4 source pixels
  208.         stosd                   ; and store them
  209.         dec     cl              ; dec counter
  210.         jnz     pl2             ; and loop..
  211.         sub     si,320          ; reset source
  212.         mov     dx,ds           ; add 32 to DS -
  213.         add     dx,32           ; move 32*16 = 512 bytes down in source memory
  214.         mov     ds,dx
  215.         dec     ch              ; dec counter
  216.         jnz     pl1             ; and loop..
  217.  
  218.         pop     ds              ; restore DS (again)
  219.         inc     word ptr [count]; increase counter
  220.         cmp     word ptr [count],10000  ; reset it at end of cycle
  221.         jne     noreset
  222.         mov     word ptr [count],0
  223.  
  224. noreset:
  225.         keyp                    ; keypressed??
  226.         jnz     closedown       ; if yes then quit..
  227.         jmp     mainloop
  228.  
  229. closedown:
  230.         mfree   [colour_seg]    ; free-up memory
  231.         mfree   [move_seg]
  232.         mfree   [plasma_seg]
  233.  
  234.         mov     ax,3h           ; set text mode...
  235.         int     10h
  236.  
  237.         end_process 0           ; byeeeeee...
  238.  
  239.  
  240. nstack  db      400 dup (?)
  241. tos     equ     $
  242.  
  243. last_inst:
  244.  
  245. END     start
  246.